import {
  autorun,
  reaction,
  intercept,
  observable,
  extendObservable,
  computed
} from 'mobx';
import {
  G3xObjBase
} from "@g3xbase"

/* 509 */
/***/

class Context extends G3xObjBase {
  constructor(g3v) {

    super();

    console.log("Context constructor!")

    let _this = this;

    extendObservable(_this, {
      _drawingBufferWidth: 0,
      _drawingBufferHeight: 0,
      _resolutionScale: 0,
      _widgetWidth: 0,
      _widgetHeight: 0,
      get drawingBufferWidth() {
        return _drawingBufferWidth;
      },
      get drawingBufferHeight() {
        return _drawingBufferHeight;
      },
      get resolutionScale() {
        return _resolutionScale;
      },
      get widgetWidth() {
        return _widgetWidth;
      },
      get widgetHeight() {
        return _widgetHeight;
      }
    }, {
      drawingBufferWidth: computed,
      drawingBufferHeight: computed,
      resolutionScale: computed,
      widgetWidth: computed,
      widgetHeight: computed
    });

    _this._disposer = g3v.viewer.clock.onTick.addEventListener(function() {
      _this._drawingBufferWidth = g3v.scene.context.drawingBufferWidth;
      _this._drawingBufferHeight = g3v.scene.context.drawingBufferHeight;
      _this._resolutionScale = g3v.viewer.resolutionScale;
      _this._widgetWidth = g3v.viewer.cesiumWidget._canvasWidth;
      _this._widgetHeight = g3v.viewer.cesiumWidget._canvasHeight;
    });
  }
  
  destory() {
    this._disposer = this._disposer && this._disposer();
  }
}

export default Context;
